01. Pirate Fleet 1 Introduction

Introduction

Introduction

Welcome to this practice session. In this session, we are going to apply what we have learned so far by modifying a battleship-style game called “Pirate Fleet”.

By the end of this session, we will write code that will create custom pirate ships, launch cannonballs, and ultimately make a playable game.

Pirate Fleet Mechanics

We are going to start this practice session off by previewing the Pirate Fleet app. But before we launch the app, let’s quickly run through an explanation of the game’s mechanics. Pirate Fleet is a clone of the classic game Battleship. The objective is simple: two players go back-and-forth trying to destroy the opposing player’s fleet.

Who won this naval battle? The world may never know...

Who won this naval battle? The world may never know…

Basic Rules

At the beginning of the game, both players place their ships onto grids unbeknownst to the other player. In total there are five ships:

  • 1 small ship (size 2)
  • 2 medium ships (size 3)
  • 1 large ship (size 4)
  • 1 extra large ship (size 5)

Normally, each ship has a special name, but we've just indicated their sizes for simplicity.

To start the game, each player places five ships onto their grid.

To start the game, each player places five ships onto their grid.

Then, each player alternates choosing a single grid location to launch their next attack. If a player chooses a grid location where a ship exists, then a HIT is recorded. If a player chooses a grid location where nothing exists, then a MISS is recorded.

Red splashes indicate a HIT, blue splashes indicate a MISS.

Red splashes indicate a HIT, blue splashes indicate a MISS.

Once a player hits every grid location for a ship, then that ship is sunk.

If every location for a ship is hit, then the ship is sunk.

If every location for a ship is hit, then the ship is sunk.

And the game ends once a player has sunk all of their opponent’s ships.

Here, the user sunk all the opponent's ships and won the game!

Here, the user sunk all the opponent's ships and won the game!

A Special Twist!

We've added our own twist to the game: underwater mines! For each player, two underwater mines can be added to the grid in the same manner as the ships. If either player chooses a grid location where a mine exists, then on the opponent's next turn they get an extra move.

When a player hits a mine, the opposing player gets an extra move!

When a player hits a mine, the opposing player gets an extra move!